<template>
  <div class="container">
    <div class="container-title">
      <p>退园管理</p>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>招商管理</el-breadcrumb-item>
        <el-breadcrumb-item>企业管理</el-breadcrumb-item>
        <el-breadcrumb-item>退园管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="search-box">
      <el-form ref="form" :model="form">
        <el-form-item
          ><el-input v-model="form.name" placeholder="企业名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="form.data" filterable placeholder="行业大类">
            <el-option
              v-for="item in industryOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="form.status" filterable placeholder="审批状态">
            <el-option
              v-for="item in approvalOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <div class="block">
          <el-date-picker
            v-model="value1"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </div>
        <el-form-item>
          <el-button
            type="success"
            @click="onSearch"
            icon="el-icon-search"
            style="background-color: #0bb197"
            >查询</el-button
          ><el-button @click="onReset" icon="el-icon-refresh" class="reset"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <!-- 表格 -->
    <div class="data-list">
      <div class="data-list-title">
        <span>查询结果列表</span>
        <el-button
          type="success"
          style="background-color: #0bb197"
          @click="publishDialog"
          >退园办理</el-button
        >
      </div>
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="id" label="序号" align="center">
        </el-table-column>
        <el-table-column prop="companyName" label="企业名称" align="center">
        </el-table-column>
        <el-table-column prop="business" label="行业大类" align="center">
        </el-table-column>

        <el-table-column label="入驻时间" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.startDate != null">{{
              timeTrans(scope.row.startDate)
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="退园时间" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.endDate != null">{{
              timeTrans(scope.row.endDate)
            }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="reason" label="退园原因" align="center">
        </el-table-column>
        <el-table-column prop="quitState" label="状态" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.quitState == 0">待审批</span>
            <span v-if="scope.row.quitState == 1">已通过</span>
            <span v-if="scope.row.quitState == 2">已撤销</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button @click="detail(scope.row)" type="text" size="small"
              >查看</el-button
            >
            <el-button
              v-if="scope.row.quitState == 0"
              @click="revoke(scope.row)"
              type="text"
              size="small"
              >撤销</el-button
            >
          </template></el-table-column
        >
      </el-table>
      <!-- 页码 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="count"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        :background="true"
      >
      </el-pagination>
    </div>

    <!-- 查看弹窗 -->
    <div class="detail-pop">
      <el-dialog
        title="详细信息"
        :visible.sync="detailDialog"
        width="43%"
        class="detail"
      >
        <div class="detail-content">
          <div class="detail-content-left">
            <ul class="detail-content-ul">
              <li>
                <span>企业名称：</span
                ><span>{{ detailShowData.companyName }}</span>
              </li>
              <li>
                <span>入驻时间：</span>
                <span v-if="detailShowData.startDate != null">{{
                  timeTrans(detailShowData.startDate)
                }}</span>
              </li>
              <li>
                <span>退园原因：</span><span>{{ detailShowData.reason }}</span>
              </li>
            </ul>
          </div>
          <div class="detail-content-right">
            <ul class="detail-content-ul">
              <li>
                <span>行业大类：</span>
                <span>{{ detailShowData.business }}</span>
              </li>
              <li>
                <span>退园时间：</span>
                <span v-if="detailShowData.endDate != null">{{
                  timeTrans(detailShowData.endDate)
                }}</span>
              </li>
              <li>
                <span>审批状态：</span
                ><span v-if="detailShowData.quitState == 0">待审批</span>
                <span v-if="detailShowData.quitState == 1">已通过</span>
                <span v-if="detailShowData.quitState == 2">已撤销</span>
              </li>
            </ul>
          </div>
        </div>
      </el-dialog>
    </div>

    <!-- 撤销弹窗 -->
    <el-dialog :visible.sync="dialogVisible" width="30%" center>
      <span center style="display: block; text-align: center"
        >请问是否确认撤销意向协定申请？</span
      >
      <span slot="footer" class="dialog-footer" center="true">
        <el-button @click="dialogVisible = false" style="background-color: #ccc"
          >取消</el-button
        >
        <el-button
          type="primary"
          @click="save"
          style="background-color: #0bb197"
          >保存</el-button
        >
      </span>
    </el-dialog>

    <!-- 退园办理弹窗 -->
    <el-dialog
      title="退园申请"
      :visible.sync="editDialog"
      width="43%"
      class="edit"
      top="6vh"
    >
      <div class="edit-content">
        <el-form :model="editData">
          <el-form-item label="企业名称">
            <el-input
              @blur="blurFn"
              v-model="editData.companyName"
              autocomplete="off"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="入驻时间">
            <el-input
              v-model="editData.startDate"
              autocomplete="off"
              placeholder="自动获取"
            ></el-input>
          </el-form-item>
        </el-form>
        <el-form :model="editData" style="margin-right: 0px">
          <el-form-item label="行业大类">
            <el-input
              v-model="editData.business"
              autocomplete="off"
              placeholder="自动获取"
            ></el-input>
          </el-form-item>
          <el-form-item label="退园时间">
            <div class="retreatPark">
              <el-date-picker
                v-model="editData.endDate"
                type="date"
                placeholder="选择日期"
              >
              </el-date-picker>
            </div>
          </el-form-item>
        </el-form>
      </div>
      <div>
        <el-form :model="editData">
          <el-form-item label="退园原因">
            <el-input
              type="textarea"
              :rows="4"
              placeholder="请输入"
              v-model="editData.reason"
            >
            </el-input>
          </el-form-item>
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button @click="editDialog = false" class="cancel">取 消</el-button>
        <el-button type="primary" @click="exitEnsure" class="save"
          >保 存</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import time from "../utils/time";
export default {
  mixins: [time],
  data: function () {
    return {
      page: 1,
      count: 5,
      total: 1,
      approvalOptions: [
        {
          value: 0,
          label: "待审批",
        },
        {
          value: 1,
          label: "已通过",
        },
        {
          value: 2,
          label: "已撤销",
        },
      ],
      form: { name: "", data: "", status: "" },
      tableData: [],
      // 下拉框
      industryOptions: [],
      twoOptions: [],
      value1: [],
      // startTime: "",
      // endTime: "",
      // 查看
      detailShowData: {},
      detailDialog: false,

      // 撤销
      dialogVisible: false,
      dialogVisibleId: 0,

      // 退园管理
      editDialog: false,
      editData: {
        id: 0,
        comparyId: 0,
        companyName: "",
        startDate: "",
        business: "",
        endDate: "",
        reason: "",
      },
      // // 退园的日历

      // // 文本域
      // textarea: "",
    };
  },
  methods: {
    // 分页
    handleSizeChange(val) {
      this.page = 1;
      this.count = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getData();
    },

    // 渲染
    getData() {
      // console.log(this.form)
      this.$axios({
        url: "/smart/company/quit/query",
        method: "post",
        params: {
          pageNum: this.page,
          pageSize: this.count,
        },
        data: {
          companyName: this.form.name,
          business: this.form.data,
          state: Number(this.form.status),
          startDate: this.value1[0],
          endDate: this.value1[1],
        },
      }).then(({ data }) => {
        // console.log("jjjjj",data);
        if (data.code == "00000") {
          this.tableData = data.data.list;
          this.total = data.data.total;
        } else {
          this.$message.error("数据加载失败！");
        }
      });
    },

    // 查询里的下拉
    getSearch() {
      this.$axios({
        url: "/smart/company/quit/query",
        method: "post",
        params: {
          pageNum: this.page,
          pageSize: this.count,
        },
        data: {
          business: "",
          companyName: "",
          state: 0,
          startDate: "",
          endDate: "",
        },
      }).then(({ data }) => {
        console.log("opopopop", data);
        if (data.code == "00000") {
          // console.log(data);
          data.data.list.forEach((v, i) => {
            let item = {
              value: v.business,
              label: v.business,
            };
            this.industryOptions.push(item);
          });
          // console.log(this.twoOptions);
          // this.twoOptions.forEach((v, i) => {});
        }
      });
    },

    onSearch() {
      this.getData();
    },
    onReset() {
      this.form = {};
      this.value1 = [];
      this.industryOptions=[]
      this.getData();
    },
    // 详情
    detail(row) {
      this.detailDialog = true;
      this.detailShowData = row;
      // console.log(this.detailShowData)
    },
    // 撤销
    revoke(row) {
      this.dialogVisible = true;
      this.dialogVisibleId = row.id;
      console.log(row);
    },
    // 撤销里的保存  更改状态未已撤销
    save() {
      this.dialogVisible = false;
      console.log(typeof this.dialogVisibleId);
      this.$axios({
        url: "/smart/company/quit/update",
        method: "put",
        data: {
          id: this.dialogVisibleId,
          quitState: 2,
        },
      }).then(({ data }) => {
        if (data.code == "00000") {
          this.$message.success("撤销成功");
          this.getData();
        }
      });
    },

    // 退园管理
    publishDialog() {
      this.editDialog = true;
    },

    blurFn() {
      // console.log(13);
      this.$axios({
        url: "/smart/company/quit/query",
        method: "post",
        params: {
          pageNum: this.page,
          pageSize: this.count,
        },
        data: {
          companyName: this.editData.companyName,
        },
      }).then(({ data }) => {
        // console.log(data);
        data.data.list.startDate &&
          (this.editData.startDate = this.timeTrans(
            data.data.list[0].startDate
          ));

        this.editData.business = data.data.list[0].business;
        this.editData.id = data.data.list[0].id;

        this.editData.comparyId = data.data.list[0].comparyId;
      });
    },
    // 退园管理的保存 保存后更改退园时间。
    exitEnsure() {
      // console.log(this.editData.comparyId);
      // console.log(this.editData.id);
      // console.log(this.editData.endDate);
      // console.log(this.editData.reason);
      this.editDialog = false;
      this.$axios({
        url: "/smart/company/quit/update",
        method: "put",
        data: {
          comparyId: this.editData.comparyId,
          id: this.editData.id,
          endDate: this.editData.endDate,
          reason: this.editData.reason,
        },
      }).then(({ data }) => {
        // console.log(data);
        if (data.code == "00000") {
          this.$message.success("申请成功");
          this.getData();
        }
      });
    },
  },
  mounted() {
    this.getData();
    this.getSearch();
  },
};
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  .container-title {
    width: 98%;
    height: 80px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    p {
      color: #333333;
      font-size: 16px;
      font-weight: 400;
      font-family: "Arial Normal", "Arial";
    }
    .el-breadcrumb-item {
      color: rgba(148, 148, 148, 0.898039215686275);
      font-size: 12px;
      font-weight: 400;
      font-family: "Arial Normal", "Arial";
    }
  }
  .search-box {
    width: 98%;
    height: 80px;
    background: #ffffff;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    border: 1px solid #ffffff;
    border-radius: 5px;
    .el-form {
      width: 98%;
      background: #ffffff;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      .el-form-item {
        margin-left: 10px;
        margin-bottom: 0;
        .el-select {
          width: 155px;
        }
        .el-button {
          margin: 10px;
        }
        .reset {
          background-color: white;
          color: #c0c4cc;
          border: 1px solid #c0c4cc;
        }
        .reset:hover {
          color: #0bb197;
        }
      }
      .block {
        margin-left: 10px;
      }
      .el-date-editor--datetimerange.el-input__inner {
        width: 310px;
      }
    }
  }
  .data-list {
    width: 98%;
    height: 100%;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-around;
    margin-top: 20px;
    .data-list-title {
      width: 98%;
      height: 60px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      span {
        height: 16px;
        font-family: "Arial Normal", "Arial";
        font-weight: 700;
        font-style: normal;
        font-size: 13px;
        color: #3c4145;
      }
    }
    .el-table {
      flex: 1;
      .el-button {
        color: #0bb197;
      }
    }
    .el-pagination {
      width: 98%;
      height: 60px;
      display: flex;
      justify-content: flex-end;
      align-items: center;
    }
  }
}

// 查看弹窗
.detail-content-left {
  flex: 1;
  margin-right: 70px;
  .detail-content-ul li {
    height: 40px;
    margin: 15px 0px;
    list-style-type: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
}
.detail-content-right {
  flex: 1;
  .detail-content-ul li {
    height: 40px;
    margin: 15px 0px;
    list-style-type: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
}

// 编辑弹窗
.edit-content {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.dialog-footer {
  text-align: center;
  .save {
    border: 0px;
    background-color: #0bb197;
  }
  .cancel:hover {
    color: #0bb197;
    border: 1px solid #0bb197;
  }
}
.retreatPark {
  position: absolute;
  top: 40px;
  left: 0px;
}
</style>
<style lang="less">
.el-pagination.is-background .el-pager li:not(.disabled):hover {
  color: #0bb197;
}
.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #0bb197;
  color: #fff;
}

/* 查看弹窗 */
.dev-content-right .cell > img {
  width: 30px;
  height: 100%;
}
.detail-pop {
  .el-dialog__header {
    background-color: #0bb197;
    padding: 10px 20px;
  }
  .el-dialog__title {
    color: white;
  }
  .el-dialog__headerbtn .el-dialog__close {
    color: white;
    font-size: 18px;
  }
  .el-dialog__headerbtn {
    top: 15px;
  }
  .detail-content {
    display: flex;
    justify-content: space-between;
  }
  .el-dialog__body {
    padding: 0px 20px;
  }
}

// 编辑弹窗
.el-form {
  width: 100%;
  margin-right: 20px;
}
.el-dialog__body {
  padding: 0px 20px;
}
.el-form-item {
  margin-bottom: 10px;
}
.el-input__inner:focus {
  border-color: #0bb197;
}
// element.style {
// height: 81px;
// display: flex;
// align-items: center;
// }
.el-table::before {
  height: 0px;
}
.el-input--prefix .el-input__inner {
  width: 325px;
}
</style>
